package service

import (
	"gitee.com/zenpk/backend-demo/internal/dal"
	"gitee.com/zenpk/backend-demo/internal/dto"
	"gitee.com/zenpk/backend-demo/internal/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ConsultStudentInfo struct{}

var consultStuInfoDal dal.ConsultStudentInfo

func (s *ConsultStudentInfo) GetByStuNum(c *gin.Context) {
	var cStuInfo dal.ConsultStudentInfo
	var req dto.GetByStuNumReq
	//请求绑定json
	if err := c.ShouldBindJSON(&req); err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetByStuNumResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	cStuInfo, err := consultStuInfoDal.GetByStuNum(req.StudentNum)

	if err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetByStuNumResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, dto.GetByStuNumResp{
		SuccessCode: 1,
		Msg:         "获取成功",
		Data:        cStuInfo,
	})
}
